<?php
	$code = $_GET["code"];
	$studentID = $_GET["studentID"];
	
	$con = mysql_connect("localhost","root","");
	if (!$con) {
		die('Could not connect: ' . mysql_error());
	}
	mysql_select_db("ciu196", $con);
	
	$sql = "SELECT * FROM `roomcode` WHERE code = '$code'";
	$res = mysql_query($sql,$con);
	if(!$res) {
		die('Error: ' . mysql_error());
	}
	$room = mysql_fetch_row($res);
	
	if($room[0] == null) {	
		die('There is no room with that code ' . $code);
	} 
	
	$roomID = $room[0];
	

	$sql = "INSERT INTO StudentsInRooms VALUES('$studentID', '$roomID', 'ok')";
	if(!mysql_query($sql,$con)) {
		die('Error couldnt insert into StudentsInRooms: ' . mysql_error());
	}
	echo "Joined Room:" . $roomID;

	mysql_close($con);	
?>